package com.orangelife.service.propfee.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import com.orangelife.common.MybaitsGenericDaoSubLogic;
import com.orangelife.service.propfee.IPropFeeLinkPublicService;
import com.orangelife.service.propfee.model.PropFeeLinkPublic;

@Service("propFeeLinkPublicService")
public class PropFeeLinkPublicServiceImpl extends MybaitsGenericDaoSubLogic
		implements IPropFeeLinkPublicService {

	@Override
	public List<PropFeeLinkPublic> getProFeeLinkPublicById(String id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		return this.getSqlSession().selectList(
				"PropFeeLinkPublicMapper.selectByPrimaryKey", map);
	}

	@Override
	public List<PropFeeLinkPublic> getProFeeLinkPublicByBean(
			PropFeeLinkPublic propFeeLinkPublic) {
		return this.getSqlSession().selectList(
				"PropFeeLinkPublicMapper.selectByBean", propFeeLinkPublic);
	}

	@Override
	public void deleteProFeeLinkPublicById(String id) {
		PropFeeLinkPublic value = new PropFeeLinkPublic();
		value.setId(id);
		value.setItemStat("0");

		this.getSqlSession().update(
				"PropFeeLinkPublicMapper.updateByPrimaryKeySelective", value);

	}

	@Override
	public void insertProFeeLinkPublicByList(
			List<PropFeeLinkPublic> propFeeLinkPublics) {

		/*
		 * this.getSqlSession().insert("PropFeeLinkPublicMapper.insertByList",
		 * propFeeLinkPublics);
		 */

		SqlSession sqlSession = this.getSqlSession();
		for (PropFeeLinkPublic propFeeLinkPublic : propFeeLinkPublics) {
			sqlSession.insert("PropFeeLinkPublicMapper.insertSelective",
					propFeeLinkPublic);
		}

	}

	@Override
	public void updateProFeeLinkPublic(PropFeeLinkPublic propFeeLinkPublic) {
		this.getSqlSession().update(
				"PropFeeLinkPublicMapper.updateByPrimaryKeySelective",
				propFeeLinkPublic);

	}

	@Override
	public List<Map<String, Object>> selectViewPropfeePropInfoByMeterId(
			String meterId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("meterId", meterId);
		return this.getSqlSession().selectList(
				"PropFeeLinkPublicMapper.selectViewPropfeePropInfoByMeterId",
				map);
	}

	@Override
	public List<Map<String, Object>> selectMeterNameByMeterId(String meterId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("meterId", meterId);
		return this.getSqlSession().selectList(
				"PropFeeLinkPublicMapper.selectMeterNameByMeterId", map);
	}

}
